const db = require('../db/index');
const moment = require('moment');

exports.addMeeting = (req, res) => {
  const { title, content, time } = req.body;
  const sql = 'INSERT INTO meeting_minutes (user_id, title, content, time) VALUES (?, ?, ?, ?)';
  db.query(sql, [req.user.id, title, content, moment(time).format('YYYY-MM-DD HH:mm:ss')], (err, results) => {
    if (err) return res.cc(err);
    if (results.affectedRows !== 1) return res.cc('添加会议纪要失败');
    res.cc('添加会议纪要成功', 0);
  });
};

exports.getMeetings = (req, res) => {
  const sql = 'SELECT * FROM meeting_minutes WHERE user_id = ?';
  db.query(sql, [req.user.id], (err, results) => {
    if (err) return res.cc(err);
    res.send({
      status: 0,
      message: '获取会议纪要成功',
      data: results
    });
  });
};